<template>
  <div class="row">
    <div class="col-3">
      <draggable
        class="list-group"
        :list="list1"
        :group="{ name: 'people', pull: true, put: false }"
      >
        <div
          v-for="(element, index) in list1"
          :key="index"
        >
          <component :is="element" />
        </div>
      </draggable>
    </div>

    <div class="col-3">
      <draggable
        class="list-group1"
        :list="list2"
        :group="{ name: 'people', pull: false, put: true }"
        @change="add2"
      >
        <div
          v-for="(element, index) in list2"
          :key="index"
          class="list-group1_item"
        >
          <component :is="element" />
        </div>
      </draggable>
    </div>
  </div>
</template>
<script>
import draggable from "vuedraggable";

export default {
  name: "two-lists",
  display: "Two Lists",
  order: 1,
  components: {
    draggable
  },
  data() {
    return {
      list1: [
        { name: "John", id: 1,template: '<div class="a1">John</div>' },
        { name: "Joao", id: 2,template: '<div class="a2">Joao</div>' },
        { name: "Jean", id: 3,template: '<div class="a3">Jean</div>' },
        { name: "Gerard", id: 4,template: '<div class="a4">Gerard</div>' }
      ],
      list2: [],
      list3: []
    };
  },
  methods: {
    add2(event) {
      let index = 0
      console.log(event)
      const movedElementIndex = this.list2.findIndex(el => el.id === event.added.element.id);  
      // if (movedElementIndex !== -1) {
      this.list2[movedElementIndex].cur = `自定义的值${index++}`;  
      // }
      console.log(this.list2, movedElementIndex);
    }
  }
}
</script>
<style>
.row{
  display: flex;
}
.list-group-item1{
  width: 100%;
  height: 40px;
  background: #666;
  margin-bottom: 10px;
}
.list-group-item2{
  width: 50%;
  height: 40px;
  background: #666;
  margin-bottom: 10px;
}
.list-group-item3{
  width: 100%;
  height: 40px;
  background: #666;
  margin-bottom: 10px;
}
.row .col-3:nth-child(1){
  flex: 0 0 300px;
  margin-right: 10px;
  border-right: 1px solid #b1b1b1
}
.row .col-3:nth-child(2){
  flex: 1;
}
.row .col-3:nth-child(3){
  flex: 0 0 300px;
  margin-left: 10px;
  border-left: 1px solid #b1b1b1
}
.a1,.a2,.a3,.a4{
  width: 50px;
  height: 50px;
}
.a1{
  background: red;
}
.a2{
  background: #666;
}
.a3{
  background: #999;
}
.a4{
  background: blue;
}
.list-group1{
}
.list-group1_item{
}
</style>